<?php

class AutoWebIdResolve extends CActiveRecordBehavior {
	public $uid = 'worker_id';
	public function beforeValidate($event) {
		$user = Yii::app()->adminUser;
		$owner = $this->getOwner();
		$webSite = Website::model()->findByAttributes(
				array('worker_id' => $owner->{$this->uid})
			);
		if($webSite && empty($this->owner->web_id)){
			$this->owner->web_id = $webSite->id;
		}
	}
}

?>